package com.example.mail.orderservice.service.impl;

import com.example.account.dto.AccountDTO;
import com.example.account.feign.AccountFeign;
import com.example.mail.orderservice.entity.Order;
import com.example.mail.orderservice.mapper.OrderMapper;
import com.example.mail.orderservice.service.OrderService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.product.dto.ProductDTO;
import com.example.product.feign.ProductFeign;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author zhou
 * @since 2022-01-10
 */
@AllArgsConstructor
@Service
public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements OrderService {

    private AccountFeign accountFeign;
    private ProductFeign productFeign;
    private OrderMapper orderMapper;

    @Override
    public void createOrder(Order order) {

        this.orderMapper.insert(order);

        ProductDTO productDTO = new ProductDTO(order.getProductCode(),order.getCount());
        this.productFeign.reduceProductStore(productDTO);

        AccountDTO accountDTO = new AccountDTO(order.getAccountCode(),order.getAmount());
        this.accountFeign.deductAmount(accountDTO);
    }
}
